package yxm.zyf.love.utils;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 
 * 类名: MedicalThreadPools
 * 包名：  com.alipayeco.medicalinscore.common.util
 * @author  Zhangyf
 * 时间：  2020年7月20日 上午9:41:33
 * 描述: TODO(请在此处详细描述类)
 * @since 1.0.0
 *
 * 修改历史 :
 * 1. [2020年7月20日]新建类 by Zhangyf
 *
 */
class MyThreadPools {

    public static ExecutorService getExecutors() {
        return executors;
    }

    private static ExecutorService executors;

    static {
        int nThreads = 10;
        
        BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(512);
        
        executors = new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, queue, new ThreadFactory() {

            private static final String threadName = "medical_thread_";

            private final AtomicInteger count = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(Thread.currentThread().getThreadGroup(), r, threadName + count.getAndIncrement());
                t.setDaemon(true);
                return t;
            }
        });
    }
}
